package com.gitee.qdbp.general.common.biz.sequence.service.model;

import com.gitee.qdbp.general.common.api.sequence.model.SimpleSequenceRule;

// {"initValue":51,"digitNumber":4,"prefix":null,"prevValue":0,"currValue":51}
public class SimpleSequenceResult extends SimpleSequenceRule {

    /** 版本序列号 **/
    private static final long serialVersionUID = 1L;

    /** 原始值 **/
    private Long prevValue;

    /** 原始值 **/
    public Long getPrevValue() {
        return prevValue;
    }

    /** 原始值 **/
    public void setPrevValue(Long prevValue) {
        this.prevValue = prevValue;
    }

    /**
     * 将当前对象转换为子类对象
     *
     * @param clazz 目标类型
     * @return 目标对象
     */
    public <T extends SimpleSequenceRule> T to(Class<T> clazz) {
        T instance = super.to(clazz);

        if (instance instanceof SimpleSequenceParams) {
            SimpleSequenceResult real = (SimpleSequenceResult) instance;
            real.setPrevValue(this.getPrevValue()); // 原始值
        }

        return instance;
    }
}
